package com.ict.controller;


import com.ict.api.dto.IctCartItemDTO;
import com.ict.api.result.ApiResponse;
import com.ict.api.vo.IctCartItemVO;
import com.ict.api.vo.IctOrderVO;
import com.ict.service.IctCartItemService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author wjp
 * @since 2025-03-23
 */
@RestController
@RequestMapping("/ict-cart-item")
public class IctCartItemController {
    @Resource
    private IctCartItemService cartService;

    @PostMapping("/add")
    public ApiResponse<String> addCartItem(@RequestBody IctCartItemDTO cartItemAddDTO) {
        return cartService.addCartItem(cartItemAddDTO);
    }

    @GetMapping("/list")
    public ApiResponse<List<IctCartItemVO>> getCartList(IctCartItemDTO cartQueryDTO) {
        return cartService.getCartList(cartQueryDTO);
    }

    @PostMapping("/update")
    public ApiResponse<String> updateCartItem(@RequestBody IctCartItemDTO cartItemUpdateDTO) {
        return cartService.updateCartItem(cartItemUpdateDTO);
    }

    @DeleteMapping("/remove")
    public ApiResponse<String> removeCartItem(@RequestParam Long cartId) {
        return cartService.removeCartItem(cartId);
    }

    /**
     * 购物车结算，生成订单
     *
     * @param cartCheckoutDTO 结算请求参数
     * @return 订单创建结果
     */
    @PostMapping("/checkout")
    public ApiResponse<IctOrderVO> checkoutCart(@RequestBody IctCartItemDTO cartCheckoutDTO) {
        return cartService.checkoutCart(cartCheckoutDTO);
    }
}

